import java.util.concurrent.atomic.AtomicInteger;

public class CASDemo {
    private static int num=0;
    private static AtomicInteger atomicInteger=new AtomicInteger(0);
    private final static int Max_num=100000;

    public static void main(String[] args) throws InterruptedException {
        Thread t1=new Thread(()->{
            for (int i = 0; i < Max_num; i++) {
                atomicInteger.getAndIncrement();//++
            }
        });
        t1.start();
        Thread t2=new Thread(()->{
            for (int i = 0; i < Max_num; i++) {
              atomicInteger.getAndDecrement();//--
            }
        });

           t2.start();
           t1.join();
           t2.join();
        System.out.println("最终结果："+atomicInteger.get());
    }
}
